package com.example.administrator.schoolblog;

import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.example.administrator.schoolblog.Widget.citypicker.CityPicker;

public class ChooseLocationActivity extends BaseActivity {
    private Toolbar toolbar;
    private CityPicker cityPicker;
    private FloatingActionButton fab;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Window window = getWindow();
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
            window.setStatusBarColor(getResources().getColor(R.color.colorPrimary));
        }
        setContentView(R.layout.blog_choose_location);
        toolbar = (Toolbar) findViewById(R.id.blog_location_toolbar);
        setSupportActionBar(toolbar);
        ActionBar actionBar = getSupportActionBar();
        if(actionBar!=null){
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setDisplayShowTitleEnabled(false);
        }
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        cityPicker = (CityPicker) findViewById(R.id.city_picker);
        fab = (FloatingActionButton) findViewById(R.id.blog_localtion_fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String location = cityPicker.GetProvince()
                        + " " + cityPicker.GetCity()
                        + " " + cityPicker.GetCounty();
                Intent intent = new Intent();
                intent.putExtra("location", location);
                setResult(RESULT_OK, intent);
                finish();
            }
        });
    }

    public static void actionStart(Activity activity, int resultCode){
        Intent intent = new Intent(activity, ChooseLocationActivity.class);
        activity.startActivityForResult(intent, resultCode);
    }
}
